<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title></title>
        <meta http-equiv="pragma" content="no-cache">
        <meta http-equiv="cache-control" content="no-cache">
        <meta http-equiv="expires" content="0">
        <link rel="stylesheet" type="text/css" href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
        <link rel="stylesheet" type="text/css"
            href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
        <script type="text/javascript"
            src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
        <script type="text/javascript" src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>   
        <script type="text/javascript"
            src="<c:url value="/static/js/common.js"/>"></script>       
        
        <script type="text/javascript" src="<c:url value="/static/js/Loading.js"/>"></script>
        
        <script>
		
			function initList(listDisplayEId) {
				$('#' + listDisplayEId).datagrid(
						{
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							toolbar : [
									{
										id : listDisplayEId + '_btn_edit',
										text : '导出送货表excel',
										iconCls : 'icon-edit',
										handler : function() {	
											var rows = $('#'+listDisplayEId).datagrid('getRows');	
											for(var i=0; i<rows.length; i++){
											    var rowIndex=$('#'+listDisplayEId).datagrid('getRowIndex',rows[i]['id']);
												$('#listDisplay').datagrid('endEdit', rowIndex);
											}
											var row = $('#'+listDisplayEId).datagrid('getRows');	
											if(row.length == 0){
												$.messager.alert('提示','无记录操作！','info');
												return;
											}else{
												var userList = new Array(); 
												var jsonFater;
												for (var i = 0 ; i < row.length;i++){
													
													var materLevelText = formatFoodType(row[i]['materLevel']);
													var storeInWayTest = formatStoreInWay(row[i]['storeInWay']);
													var storeInStateTest = formatStoreInState(row[i]['storeInState']);
													var accountStateTest = formatAccountState(row[i]['accountState']);
													var  jsonSun = "{id:'"+row[i]['id']+"',storeInId:'"+row[i]['storeInId']+"',storeHouseId:'"+row[i]['storeHouseId']+"',storeName:'"+row[i]['storeName']+"',custId:'"+row[i]['custId']+"',custName:'"+row[i]['custName']+"',supId:'"+row[i]['supId']+"',supName:'"+row[i]['supName']+"',materId:'"+row[i]['materId']+"',materName:'"+row[i]['materName']+"',materLevel:'"+materLevelText+"',storeInWay:'"+storeInWayTest+"',storeInState:'"+storeInStateTest+"',creatDate:'"+row[i]['creatDate']+"',materNum:'"+row[i]['materNum']+"',materValue:'"+row[i]['materValue']+"',accountState:'"+accountStateTest+"',accountDate:'"+row[i]['accountDate']+"'}";
													
													userList.push(jsonSun);
												}
												jsonFater = JSON.stringify(userList);
												var str = "json="+jsonFater;	
												document.getElementsByName("excelList")[0].value = jsonFater;
												
												excel();
											}
										}
									}
									],
							onLoadError:function(){
								$.messager.alert('错误','获取数据失败，请与管理员联系！','error');
							}
						 ,onClickRow:function(rowIndex){
								$(".myrad").prop("checked",false);
								$(".myrad").eq(rowIndex).prop("checked",true);
								var row = $('#'+listDisplayEId).datagrid('getRows');
								if (row[0]['storeInWay'] == "2"){
									$('#listDisplay').datagrid('beginEdit', rowIndex);
								} 
							} 
						});
			};
			$(document).ready(function() {
				initList('listDisplay');
			});
			
			  
		    
			function excel(){
				$('#AddFoodForm').form('submit',
		 				{
		 					url:'<c:url value='/supplier/exportSupperExcelPrintCost.do'/>', //查询提交路径
		 					onSubmit:function()//提交按钮相应函数
		 					{
		 						var Allwidth = '100%';
		 		                var Allheight = '100%';
		 		                Loading.Show({width:Allwidth,height:Allheight});
		 		                setTimeout(function(){
		 		                    Loading.Hide();
		 		                },3000)
		 		                //校验
                                if($('#orderDate').datebox('getValue') ==''){
                                    $.messager.alert('提示','订单日期没有填写！','info');
                                    closeShow();
                                }
		 						return $('#AddFoodForm').form('validate');
		 					},
		 					success:function(data){
                                $.messager.alert("提示", "价格没有导入！请先导入报表价格！", 'warning');
		                       /*  data = eval( "("+data+")" );

		                        if(data.success){
		                            $.messager.alert("提示", "提交成功！", 'info');
		                        }else{
		                        	alert(1);
		                            var message = "";
		                            if(data.msg == "msg002"){
		                                message = "所选择日期的材料订单已经下单完成，如需重新选择请删除已有订单。";
		                            }else if(data.msg == "msg001"){
		                                message = "选择材料的时间已过，请联系采购部。";
		                            }else if(data.msg == "msg0001"){
		                            	message = "价格没有导入！请先导入报表价格！";
		                            }
		                            $.messager.alert("提示", message, 'warning');
		                        } */
		                    },
		                    error:function(){
		                        $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
		                        return;
		                    }
		 				});
				
				
			}
			function closeShow(){
				Loading.Hide();
			}
		</script>
			</head>
			<body>
			<table width="98%">
			<tr><td>
				<form id="AddFoodForm" name="AddFoodForm" method="post">
				<div style="height: auto; width:1180px;background: #fafafa; padding: 5px;" class="easyui-panel" title="送货报表导出打印" iconCls="icon-add" collapsible="true" minimizable="false" maximizable="false" closable="false">
			    <table cellpadding="5">
			      <tr>
                  	<td>日期</td>
                    <td>
 			            <input class="easyui-datebox" name="orderDate" id="orderDate" editable="false" data-options="required:true"/> 
 			        </td>
 			        <td>
 			        	<a href="#" class="easyui-linkbutton" onclick="excel();">导出</a>
 			        </td>
                  </tr>
				        <input class="easyui-validatebox" type="hidden" name="idList"  />
				        <input class="easyui-validatebox" type="hidden" name="excelList"  />
				        <input class="easyui-validatebox" type="hidden" name="footList"  />
				        <input class="easyui-validatebox" type="hidden" name="supId" value="0"  />
                </table>
                </div>
                </form>
            </td></tr>
            </table>
			<table width="98%">
			<tr>
		</table>
	</body>
</html>